$(document).ready(function () {
    //粒子背景特效
    $('body').particleground({
        dotColor: '#5c9bbd',
        lineColor: '#5c9bbd'
    });
    var canvas = document.querySelector("canvas");
    //页面窗口大小改变时触发
    $(window).resize(function () {
        //获取浏览器窗口文档显示区域的宽度，不包括滚动条
        canvas.width = document.documentElement.clientWidth;
        //获取浏览器窗口文档显示区域的高度度，不包括滚动条
        canvas.height = document.documentElement.clientHeight;
        $('#item').width($(window).width());
    });
    //禁止浏览器回退到上一个页面
    if (window.history && window.history.pushState) {
        $(window).on('popstate', function () {
            window.history.pushState('forward', null, '#');
            window.history.forward(1);
        });
    }
    //在IE中必须得有这两行
    window.history.pushState('forward', null, '#');
    window.history.forward(1);
});
//按回车键 触发登录
$(".input").keydown(function (e) {
    if (e.keyCode == 13) {
        login();
    }
});
//登录
$(".submit_btn").on("click", function () {
    login();
});

function login() {
    var account = $('#account').val();
    var password = $('#password').val();
    if (account.length == 0 || password.length == 0 || account.trim().length == 0 || password.trim().length == 0) {
        return false;
    }
    var data = {"account": $.base64.encode(account), "password": $.base64.encode(password)};
    $.ajax({
        type: "post",
        url: "login",
        contentType: "application/json;charset=UTF-8",
        data: JSON.stringify(data),
        success: function (result) {
            if (result.code == 200) {
                location.href = './index';
            } else {
                parent.layer.msg(result.msg)
            }
        },
        error: function (result) {
            parent.layer.msg(result.msg)
        }
    });
}